package com.yaozheng.vocationaltraining.service.impl.set_up;

import com.yaozheng.vocationaltraining.iview.BaseView;
import com.yaozheng.vocationaltraining.iview.set_up.ISuggestView;
import com.yaozheng.vocationaltraining.service.set_up.SuggestService;
import com.yaozheng.vocationaltraining.utils.Constants;
import com.yaozheng.vocationaltraining.utils.ErrorUtils;
import com.yaozheng.vocationaltraining.utils.http.okhttp.OkHttpClientManager;

import net.sf.json.JSONObject;

import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.EBean;

import java.util.HashMap;
import java.util.Map;

/**
 * 意见反馈
 */
@EBean
public class SuggestServiceImpl implements SuggestService {
    ISuggestView iSuggestView;

    @Override
    public void init(ISuggestView iSuggestView) {
        this.iSuggestView = iSuggestView;
    }

    @Background
    @Override
    public void suggest(String content, String mobile) {
        try {
            HashMap para = new HashMap();
            para.put("content", content);
            para.put("mobile", mobile);
            OkHttpClientManager.getInstance().post(
                    Constants.ROOTURL + "/system/suggest",
                    iSuggestView.getToken(), para,
                    new OkHttpClientManager.IBaseViewCallback(new BaseView(iSuggestView) {

                        @Override
                        public void responseSuccess(JSONObject jsonObject) {
                            iSuggestView.suggestSuccess(jsonObject);
                        }

                        @Override
                        public void responseError(String error) {
                            iSuggestView.suggestError(error);
                        }


                    }));
        } catch (Exception e) {
            ErrorUtils.outErrorLog(e);
            if (iSuggestView.isResponseResult()) {
                iSuggestView
                        .suggestError(ErrorUtils.SERVER_CONNECTION_ERROR);
            }

        }
    }
}
